home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / rbbs_pc / mnt_201.zip / RBBSMNT.C < prev    next >
C/C++ Source or Header  |  1992-01-05  |  12KB  |  383 lines

  1. /****************************************************************************/
  2. /* RBBSMNT v2.01, a maintenance utility for RBBS-PC                         */
  3. /*╒═════════════════════════════ NOTICE ═══════════════════════════════════╕*/
  4. /*│  A limited license is granted to all users of this program to make     │*/
  5. /*│  copies if this program and distribute those copies to other users     │*/
  6. /*│  on the following three conditions:                                    │*/
  7. /*│                                                                        │*/
  8. /*│    1.   This notice is NOT altered, bypassed or removed,               │*/
  9. /*│    2.   The program is not to be distributed to others in modified     │*/
  10. /*│         form. You may make changes for your own non-commercial use     │*/
  11. /*│    3.   No fee is to be charged (or any other consideration received)  │*/
  12. /*│         for copying or distributing these programs without an express  │*/
  13. /*│         written agreement with J. Terpstra, Bamestra RBBS, PO Box 66,  │*/
  14. /*│         Beemster, The Netherlands.                                     │*/
  15. /*│                                                                        │*/
  16. /*│Copyright (C) 1991, 1992 - Jan Terpstra, Bamestra RBBS, The Netherlands.│*/
  17. /*╘════════════════════════════════════════════════════════════════════════╛*/
  18. /****************************************************************************/
  19.  
  20. #include "rbbsmnt.h"                    /* definitions for this program     */
  21. #include "externs.h"                    /* external data references         */
  22.  
  23.   /**************************************************************************/
  24.   /* main                                                                   */
  25.   /**************************************************************************/
  26.  
  27. FILE *logfile;
  28. int logging = FALSE;
  29. main(int argc,char *argv[])
  30. {
  31.    int n;
  32.    long t_start;
  33.  
  34.    printf("\n     "PRGNAME VERSION RELDATE
  35.    "- a maintenance utility for RBBS-PC.\n");
  36.    printf("(C)1991, 1992 by J.R. Terpstra of Bamestra RBBS, The Netherlands (2:512/10.0)\n\n");
  37.  
  38.    if (argc < 2)
  39.    {
  40.       printf("Usage: RBBSMNT [options]\n\nOptions are:\n\n");
  41.       printf(" -w  workdir   drive\\path to be used as workdir, preferably a VDISK.\n"
  42.       );
  43.       printf(" -l  logfile   the name of the logfile to use.\n");
  44.       printf(" -m  msgfile   the name of the msgfile to process.\n");
  45.       printf(" -km N         maximum age of msgs (n = 1...32767).\n");
  46.       printf(" -mm N         maximum number of msgs that will be left in the\
  47.  msgfile after\n");
  48.       printf("               processing is done (n = 1...999).\n");
  49.       printf
  50.       (" -r            renumber msgs in msgsfile. Requires usrfile too!\n");
  51.       printf(" -pip          Pack in place, do not use temporary file.\n");
  52.       printf(" -s            Save old messages to a file XXXX.NNN, where XXX\
  53. X is the name of\n");
  54.       printf("               conference and NNN is the current daynumber.\n"
  55.       );
  56.       printf(" -u usrfile    name of usrfile to process.\n");
  57.       printf(" -ku N         days of inactivity before user is deleted (n = \
  58. 1...32767).\n");
  59.       printf
  60.       (" -xu N         user level exempted from cleanup (n = 1...32767).\n")
  61.       ;
  62.       printf (" -q            quiet, minimum progress indication. Runs faster.\n");
  63.       printf(" -fix          repair message file's HEADER & NODE records.\n");
  64.       printf("Press any key to continue...");
  65.       getch();
  66.       printf("\rSome Examples:           \n");
  67.       printf("RBBSMNT -w E:\\ -m MESSAGES -r -km 60 -mm 200 -r  -u USERS -ku\
  68.  60 -xu 10\n");
  69.       printf(" Removes killed msgs and all msgs older than 60 days from file\
  70.  MESSAGES.\n");
  71.       printf(
  72.       " If needed, removes additional msgs untill 200 msgs are left.\n");
  73.       printf(" Renumbers msgs in file MESSAGES, update last msg read for all\
  74.  users. Then\n");
  75.       printf(" cleans USERS file from users that have not logged on for 60 d\
  76. ays or more,\n");
  77.       printf(" except users with access level 10 or higher. Uses Drive E:\\ \
  78. as workdir.\n\n");
  79.       printf("RBBSMNT -m IBMPCM.DEF -mm 5000 -q\n");
  80.       printf(
  81.   " Removes killed msgs and as many additional msgs until a maximum of 500\n"
  82.       );
  83.       printf
  84.       (" msgs is left in the file IBMPCM.DEF. Runs in quiet mode.\n\n");
  85.       printf(
  86.       "RBBSMNT -m TENNISM.DEF -r -u TENNISU.DEF -ku 90 -l RBBSMNT.LOG\n"
  87.       );
  88.       printf(" Renumbers msgs in the file TENNISM.DEF, adjusts the last msg \
  89. read pointers\n");
  90.       printf(" in the file TENNISU.DEF. Deletes users that have not logged o\
  91. n for 90 days.\n");
  92.       printf(" Writes activities and deleted users to RBBSMNT.LOG.\n\n");
  93.       printf(
  94.       "RBBSMNT -m TENNISM.DEF -fix\n"
  95.       );
  96.       printf(" Repair header & node records of messages file TENNISM.DEF.\n");
  97.       exit(0);
  98.    }
  99.  
  100.    /*************************************************************************/
  101.    /* process commandline options                                           */
  102.    /*************************************************************************/
  103.  
  104.  
  105.    for (n = 1; n < argc; n++)
  106.    {
  107.       strupr(argv[n]);
  108.  
  109.       /**********************************************************************/
  110.       /* msgfile options                                                    */
  111.       /**********************************************************************/
  112.  
  113.  
  114.       if (!stricmp(argv[n], "-M"))      /* MESSAGES filename                */
  115.       {
  116.          n++;
  117.  
  118.          if (n == argc)
  119.          {
  120.             bad_arg(argv[n-1]);
  121.          }
  122.          msgfile = argv[n];
  123.          strupr(msgfile);
  124.          continue;
  125.       }
  126.  
  127.       if (!stricmp(argv[n], "-KM"))     /* max age of messages              */
  128.       {
  129.          n++;
  130.  
  131.          if (n == argc)
  132.          {
  133.             bad_arg(argv[n-1]);
  134.          }
  135.          max_age = atoi(argv[n]);
  136.          do_clean = TRUE;
  137.          continue;
  138.       }
  139.  
  140.       if (!stricmp(argv[n], "-MM"))     /* max # of msgs to leave           */
  141.       {
  142.          n++;
  143.  
  144.          if (n == argc)
  145.          {
  146.             bad_arg(argv[n-1]);
  147.          }
  148.          max_msgs = atoi(argv[n]);
  149.          do_clean = TRUE;
  150.          continue;
  151.       }
  152.  
  153.       if (!stricmp(argv[n], "-R"))
  154.       {
  155.          do_renum = TRUE;
  156.       }
  157.  
  158.       if (!stricmp(argv[n], "-S"))
  159.       {
  160.          save_em = TRUE;
  161.       }
  162.  
  163.       if (!stricmp(argv[n], "-PIP"))
  164.       {
  165.          pip = TRUE;
  166.       }
  167.  
  168.       if (!stricmp(argv[n], "-FIX"))
  169.       {
  170.          fixhdr = TRUE;
  171.       }
  172.  
  173.       /**********************************************************************/
  174.       /* user file options                                                  */
  175.       /**********************************************************************/
  176.  
  177.  
  178.       if (!stricmp(argv[n], "-U"))      /* USERS file                       */
  179.       {
  180.          n++;
  181.  
  182.          if (n == argc)
  183.          {
  184.             bad_arg(argv[n-1]);
  185.          }
  186.          usrfile = argv[n];
  187.          strupr(usrfile);
  188.          continue;
  189.       }
  190.  
  191.       if (!stricmp(argv[n], "-KU"))     /* max age of users                 */
  192.       {
  193.          n++;
  194.  
  195.          if (n == argc)
  196.          {
  197.             bad_arg(argv[n-1]);
  198.          }
  199.          max_since = atoi(argv[n]);
  200.          do_usr = TRUE;
  201.          continue;
  202.       }
  203.  
  204.       if (!stricmp(argv[n], "-XU"))     /* exempt users                     */
  205.       {
  206.          n++;
  207.  
  208.          if (n == argc)
  209.          {
  210.             bad_arg(argv[n-1]);
  211.          }
  212.          exempt = atoi(argv[n]);
  213.          continue;
  214.       }
  215.  
  216.       /**********************************************************************/
  217.       /* misc options                                                       */
  218.       /**********************************************************************/
  219.  
  220.  
  221.       if (!stricmp(argv[n], "-Q"))
  222.       {
  223.          quiet = TRUE;
  224.       }
  225.  
  226.       if (!stricmp(argv[n], "-L"))      /* log to file?                     */
  227.       {
  228.          n++;
  229.  
  230.          if (n == argc)
  231.          {
  232.             bad_arg(argv[n-1]);
  233.          }
  234.  
  235.          if ((logfile = fopen(argv[n], "a+")) == NULL)
  236.          {
  237.             printf("\n!Cannot open logfile.\n");
  238.          }
  239.  
  240.          else
  241.          {
  242.             sprintf(logbuf, "Begin "PRGNAME VERSION);
  243.             writelog(logbuf, 0, 2);     /* log start time                   */
  244.             logging = TRUE;
  245.          }
  246.          continue;
  247.       }
  248.  
  249.       if (!stricmp(argv[n], "-W"))      /* workdir                          */
  250.       {
  251.          n++;
  252.  
  253.          if (n == argc)
  254.          {
  255.             bad_arg(argv[n-1]);
  256.          }
  257.          strcpy(wkf, argv[n]);
  258.  
  259.          if (wkf[strlen(wkf)-1] == '\\')/* zap trailing backslash           */
  260.          {
  261.             wkf[strlen(wkf)-1] = '\0';
  262.          }
  263.          strupr(wkf);
  264.          use_wrk = TRUE;
  265.          continue;
  266.       }
  267.    }
  268.    t_start = time(NULL);
  269.  
  270.    /*************************************************************************/
  271.    /* allocate room for msg and user list                                   */
  272.    /*************************************************************************/
  273.    if(pip)
  274.    {
  275.       use_wrk = FALSE;
  276.    }
  277.  
  278.    if (fixhdr)
  279.    {
  280.       repair();
  281.    }
  282.  
  283.    if ((mlist = (MSGINFO_PTR)calloc(1024, sizeof(MSGINFO))) == NULL)
  284.    {
  285.       sprintf(logbuf, "%s messages list.", no_memory);
  286.       writelog(logbuf, 1, 0);
  287.       exit(2);
  288.    }
  289.  
  290.    if (do_usr)
  291.    {
  292.  
  293.       if ((hlist = (char far *)calloc(32767, sizeof(char))) == NULL ||
  294.       (ulist = (RBBSUSER_PTR)calloc(UBLOCK, sizeof(RBBSUSER))) == NULL)
  295.       {
  296.          sprintf(logbuf, "%s users list.", no_memory);
  297.          writelog(logbuf, 1, 0);
  298.          exit(2);
  299.       }
  300.  
  301.       /**********************************************************************/
  302.       /* fill "used records" list                                           */
  303.       /**********************************************************************/
  304.  
  305.       memset((char *)hlist, 'F', 32767);
  306.       memset((char *)ulist, ' ', UBLOCK *sizeof(RBBSUSER));
  307.  
  308.       /**********************************************************************/
  309.       /* prepare a block of 256 user records                                */
  310.       /**********************************************************************/
  311.  
  312.  
  313.       for (n = 0; n < UBLOCK; n++)
  314.       {
  315.          ulist[n].user_level = -32000;
  316.       }
  317.    }
  318.    time(<ime);                        /* get current date/time            */
  319.    today = localtime(<ime);
  320.    now = (int)(((today->tm_year-80)*365)+to_month[today->tm_mon]+
  321.    today->tm_mday);
  322.  
  323.    if (do_clean || do_renum)
  324.    {
  325.       cleanmsg();
  326.    }
  327.  
  328.    if (do_usr)
  329.    {
  330.       cleanusr();
  331.    }
  332.    sprintf(logbuf, PRGNAME VERSION" done in %d sec.\n", (int)(time(NULL)-
  333.    t_start));
  334.    printf("+ %s", logbuf);
  335.  
  336.    if (logfile)
  337.    {
  338.       writelog(logbuf, 0, 2);
  339.       fclose(logfile);
  340.    }
  341.    return (0);
  342. }
  343.  
  344.  
  345.   /**************************************************************************/
  346.   /* complain about bad argument for option                                 */
  347.   /**************************************************************************/
  348.  
  349. void bad_arg(char *a)
  350. {
  351.    printf("Bad argument for switch \"%s\"\n, please perform RTFM\n", a);
  352.    exit(2);
  353. }
  354.  
  355.  
  356.   /**************************************************************************/
  357.   /* write to logfile                                                       */
  358.   /**************************************************************************/
  359.  
  360. void writelog(char *logmsg,int flag,int l)
  361. {
  362.    char buf[TXTLEN],*ds;
  363.    static char s[] = "!*+: ";
  364.  
  365.    time(<ime);                        /* get current date/time            */
  366.    ds = asctime(localtime(<ime));
  367.  
  368.    if (flag)
  369.    {
  370.       printf("\r%c %s\n", s[l], logmsg);
  371.    }
  372.       sprintf(buf, "%c %.2s %.3s %.8s RMNT %s\n", s[l], ds+8, ds+4, ds+11, logmsg);
  373.  
  374.    if (logfile)
  375.    {
  376.       fputs(buf, logfile);
  377.    }
  378. }
  379.  
  380.  
  381. /*--------------------------------------------------------------------------*/
  382.  
  383.